using SqlSugar;

namespace ChatBackend.Models
{
    [SugarTable("Messages")]
    public class Message
    {
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }

        [SugarColumn(IsNullable = false)]
        public int ChatRoomId { get; set; }

        [SugarColumn(IsNullable = false)]
        public int SenderId { get; set; }

        [SugarColumn(Length = 2000, IsNullable = false)]
        public string Content { get; set; } = string.Empty;

        [SugarColumn(IsNullable = false)]
        public MessageType Type { get; set; } = MessageType.Text;

        [SugarColumn(IsNullable = false, ColumnDataType = "TEXT")]
        public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

        [SugarColumn(IsNullable = false)]
        public bool IsEdited { get; set; } = false;

        [SugarColumn(IsNullable = true, ColumnDataType = "TEXT")]
        public DateTime? EditedAt { get; set; }

        [SugarColumn(IsNullable = false)]
        public bool IsDeleted { get; set; } = false;

        // 导航属性
        [SugarColumn(IsIgnore = true)]
        public User? Sender { get; set; }

        [SugarColumn(IsIgnore = true)]
        public ChatRoom? ChatRoom { get; set; }
    }

    public enum MessageType
    {
        Text = 1,
        Image = 2,
        File = 3,
        System = 4
    }
}
